﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using log4net;
namespace LSW.Wcf.App
{
    public static class Utility
    {
        public static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public static bool IsSunday(string dayString)
        {
            string[] date = dayString.Split('/');
            if(date.Count() != 3) return false;
 
            int year;
            if(!int.TryParse( date[0], out year)) return false;

            int month;
            if(!int.TryParse( date[1], out month)) return false;
            
            int day;
            if(!int.TryParse( date[2], out day)) return false;

            try
            {
                DateTime datetime = new DateTime(year, month, day);
                return datetime.DayOfWeek == DayOfWeek.Sunday;
            }
            catch { }
            return false;
        }

        public static string GetConnectString()
        {
            return System.Configuration.ConfigurationManager.ConnectionStrings["LSWData"].ConnectionString;
        }

        public static void SetDBNull(this DbParameter[] Parameters)
        {
            foreach (DbParameter p in Parameters)
            {
                if (p.Value == null)
                    p.Value = DBNull.Value;

                if (p.Value.GetType() == typeof(Guid))
                {
                    if (Guid.Empty.ToString() == p.Value.ToString())
                    {
                        p.Value = DBNull.Value;
                    }
                }

                if (p.Value.GetType() == typeof(DateTime))
                {
                    DateTime date = Convert.ToDateTime(p.Value);
                    if (date == DateTime.MinValue)
                    {
                        p.Value = DBNull.Value;
                    }
                }
            }
        }
    }
}